﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public interface IComponent
{
    string GetDescription();
    void RecoverHP(int hp);
    int MagicDamage();
}


public class Character : IComponent
{
    private string _name;
    public int HP { get; private set; }
    public Character(string name)
    {
        _name = name;
        HP = 10;
    }
    public virtual string GetDescription()
    {
        return string.Format("Character {0}[{1}]", _name, HP);
    }
    public virtual void RecoverHP(int hp)
    {
        HP += hp;
    }
    public virtual int MagicDamage()
    {
        return 100;
    }
}


public abstract class Clothing : IComponent
{
    protected IComponent _component;
    public Clothing(IComponent componet)
    {
        _component = componet;
    }
    public virtual string GetDescription()
    {
        return _component.GetDescription();
    }
    public virtual void RecoverHP(int hp)
    {
        _component.RecoverHP(hp);
    }
    public virtual int MagicDamage()
    {
        return _component.MagicDamage();
    }
}


public class RedHat : Clothing
{
    public RedHat(IComponent componet) : base(componet)
    {
    }
    public override string GetDescription()
    {
        return base.GetDescription() + " in red hat[Rec + 10%]";
    }
    public override void RecoverHP(int hp)
    {
        hp += (int)(hp * 0.1f);
        base.RecoverHP(hp);
    }
}


public class Robe : Clothing
{
    private int _magicPlus;
    public Robe(IComponent componet, int magP) : base(componet)
    {
        _magicPlus = magP;
    }
    public override string GetDescription()
    {
        return base.GetDescription() + string.Format(" in robe[Mag + {0}]", _magicPlus);
    }
    public override int MagicDamage()
    {
        return base.MagicDamage() + _magicPlus;
    }
}



public class Decorator : MonoBehaviour
{

    void Start()
    {
        IComponent component = new Robe(new RedHat(new Character("X")), 10);
        component.RecoverHP(10);
        Debug.Log(component.GetDescription());
        Debug.Log(component.MagicDamage());
    }

 
}
